package com.c.ctgproject.ui.vehiclelocation

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.c.ctgproject.mode.VehicleLocation
import com.c.ctgproject.retrofit.HttpHelper
import com.c.ctgproject.retrofit.Response
import com.c.ctgproject.retrofit.Service
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

class VehicleLocationViewModel:ViewModel() {
    private val responsedata : MutableLiveData<Response<VehicleLocation>> = MutableLiveData()
    private val PostcarMovedata : MutableLiveData<Response<*>> = MutableLiveData()
    private val serviece = HttpHelper.getInstance().create(Service::class.java)

    fun getresponsedata():MutableLiveData<Response<VehicleLocation>>{
        return  responsedata
    }
    fun getPostcarMovedata():MutableLiveData<Response<*>>{
        return  PostcarMovedata
    }

    //车辆库位
    fun carMove(token:String, cardCode:String){
        serviece.carMove(token,cardCode)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<Response<VehicleLocation>> {
                override fun onError(e: Throwable) {
                    Log.d("错误信息", ""+e.message)
                    e.printStackTrace()
                }

                override fun onComplete() {}
                override fun onSubscribe(d: Disposable) {}
                override fun onNext(data: Response<VehicleLocation>) {
                    responsedata.value = data
                }
            })
    }

    //车辆移库
    fun PostcarMove(token:String,carId:String,warehouseId:String){
        serviece.PostcarMove(token,carId,warehouseId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<Response<VehicleLocation>> {
                override fun onError(e: Throwable) {
                    Log.d("错误信息", ""+e.message)
                    e.printStackTrace()
                }

                override fun onComplete() {}
                override fun onSubscribe(d: Disposable) {}
                override fun onNext(data: Response<VehicleLocation>) {
                    PostcarMovedata.value = data
                }
            })
    }
}